package pub.pjoc.config.aop;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * @author xiongyingqi
 * @since 16-11-30 下午3:50
 */
public abstract class AbstractCacheService<T> {
  private static final Logger logger = LoggerFactory.getLogger(AbstractCacheService.class);
  protected Class<T> pojoType;

  @SuppressWarnings("unchecked")
  public AbstractCacheService() {
    Type genericSuperclass = this.getClass().getGenericSuperclass();
    try {
      Type type = ((ParameterizedType) genericSuperclass).getActualTypeArguments()[0];
      pojoType = (Class<T>) type;
      logger.info("constructor... genericSuperclass: {}, pojoType: {}", genericSuperclass,
          pojoType);
    } catch (ClassCastException e) {
      logger.error("subclass must preset a generic class!", e);
    }
  }
}
